function StringBuffer() {
	this.buffer = [];

	this.append = function(arg) {
		this.buffer.push(arg);
		return this;
	};

	this.toString = function() {
		return this.buffer.join("");
	};
} 
var delayAMoment = (function(){
  var timer = 0;
  return function(callback, ms){
    clearTimeout (timer);
    timer = setTimeout(callback, ms);
  };
})();
/**
 * Replaces {0}, {1}, {2}, etc... in the string with the corresponding parameter
 * based on parameter index.
 * 
 * @returns
 */
String.prototype.format = function() {
	var args = arguments;
	return this.replace(/{(\d+)}/g, function(match, number) {
		return typeof args[number] != 'undefined' ? args[number] : match;
	});
}; 

MYLIB.execFunction = function (fn, args) {
    if (fn == null) return;
    if (fn.perform != null) {
        var applyArgs = [];
        
        if (typeof args !== "undefined") {
            applyArgs = applyArgs.concat(args);
        }
        
        var callbackArgs = fn.getArgs();
        if (callbackArgs != null) {
            applyArgs = applyArgs.concat(callbackArgs);
        }
        
        fn.perform(applyArgs);
    } else if ($.isFunction(fn)) {
        if ($.isArray(args)) {
            fn.apply(null, args);
        } else {
            fn.call(null, args);
        }
    }
};

/**
 * Convert an image 
 * to a base64 string
 * @param  {String}   url         
 * @param  {Function} callback    
 * @param  {String}   [outputFormat=image/png]           
 */
MYLIB.convertImgToBase64 = function(url, callback, outputFormat){
    var canvas = document.createElement('CANVAS'),
        ctx = canvas.getContext('2d'),
        img = new Image;
    img.crossOrigin = 'Anonymous';
    img.onload = function(){
        var dataURL;
        canvas.height = img.height;
        canvas.width = img.width;
        ctx.drawImage(img, 0, 0);
        dataURL = canvas.toDataURL(outputFormat);
        callback.call(this, dataURL);
        canvas = null; 
    };
    img.src = url;
}